var t = function (t) {
  return t && t.__esModule ? t : {
    default: t
  };
}(),
  app = getApp(),
  e = 0;
var page = 1;
Page({
  data: {
    list_t: [],
    tabpid: 0,
    curHdIndex: 1,
    index: 5,
    pageOne: 0,
    pageTwo: 0,
    prenumber: 20,
    tsid: 1,
    loadingBoo: !0,
    moreBooOne: !0,
    moreBooTwo: !0,
    communityListOne: [],
    communityListTwo: [],
    url: "patient/community/list/",
    oneBoo: !1,
    twoBoo: !1,
    mask: !0,
    currindex: 0,
    itemList: [],
    ismore: true,
    bigMask: true,

    footer: {
      footerTab: 2,
      footerlist: [{
        text: "首页",
        img: "/hyb_yl/images/tab01.png",
        selimg: "/hyb_yl/images/tab1.png",
        url: "/hyb_yl/tabBar/index/index"
      }, {
        text: "资讯",
        img: "/hyb_yl/images/tab02.png",
        selimg: "/hyb_yl/images/tab2.png",
        url: "/hyb_yl/tabBar/jibingyufang/jibingyufang"
      }, {
        text: "分享",
        img: "/hyb_yl/images/tab03.png",
        selimg: "/hyb_yl/images/tab3.png",
        url: "/hyb_yl/tabBar/community/community"
      }, {
        text: "药房",
        img: "/hyb_yl/images/tab04.png",
        selimg: "/hyb_yl/images/tab4.png",
        url: "/hyb_yl/tabBar/shop/shop"
      }, {
        text: "问诊",
        img: "/hyb_yl/images/tab04.png",
        selimg: "/hyb_yl/images/tab4.png",
        url: "/hyb_yl/tabBar/fastnavigate/fastnavigate"
      }, {
        text: "我的",
        img: "/hyb_yl/images/tab05.png",
        selimg: "/hyb_yl/images/tab5.png",
        url: "/hyb_yl/tabBar/my/my"
      }]
    },
    tabindex: 0,
    deparshow: false,
  },
  tabChose: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    that.setData({
      tabchoseStyle: index,
      tabcid: e.currentTarget.dataset.tabcid
    })
  },
  departab: function (e) {
    var that = this;
    const tabindex = e.currentTarget.dataset.dex;
    console.log(tabindex);

    if (tabindex == 0) {
      var tabpid = 0;
    } else {
      var tabpid = e.currentTarget.dataset.tabpic;
    }
    var page = 0
    that.setData({
      tabindex: tabindex,
      tabpid: tabpid,
      page: 0,
      communityListOne: []
    })
    that.getAllshare(page, tabpid)
  },
  deparlist: function () {
    if (this.data.deparshow) {
      this.setData({
        deparshow: false
      })
    } else {
      this.setData({
        deparshow: true
      })
    }
  },
  departabs: function (e) {
    var that = this;
    const index = e.currentTarget.dataset.dex;
    if (index == 0) {
      var tabpid = 0;
    } else {
      var tabpid = e.currentTarget.dataset.tabpic;
    }
    var page = 0
    that.setData({
      tabindex: index,
      deparshow: false,
      tabpid: tabpid,
      page: 0,
      communityListOne: []
    })
    that.getAllshare(page, tabpid)


  },
  navto: function (e) {
    var url = e.currentTarget.dataset.url
    wx.navigateTo({
      url: url,
    })
  },
  goback: function (e) {
    var index = e.currentTarget.dataset.index + 1
    var tabpic = e.currentTarget.dataset.tabpic;
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/dynamic/dynamic?index=' + index + '&tabpic=' + tabpic,
    })
  },
  //tab切换
  list: function (e) {
    var that = this;
    console.log(e)
    if (e.currentTarget.dataset.id == 1) {
      console.log('123')
      that.setData({
        curHdIndex: 1
      })
    } else {
      //热门
      that.setData({
        curHdIndex: 2
      })
    }
    if (e.currentTarget.dataset.id == 2) {
      app.util.request({
        url: 'entry/wxapp/share.remen',
        data: {
          openid: wx.getStorageSync('openid'),
          state: 0
        },
        success: function (res) {
          console.log(res)
          that.setData({
            communityListOne: res.data,
          })
        }
      })
    } else {

      this.getAllshare(0, 0)
    }
  },
  //上来加载
  // moreState: function() {
  //   var a = this,
  //     e = {
  //       type: a.data.curHdIndex,
  //       tsid: a.data.tsid,
  //       token: a.data.token
  //     },
  //     n = a.data.prenumber;
  //   t.default.getCommunityList(a, e, n);
  // },
  //点赞
  toLike: function (a) {
    var e = this;
    let communityListOne = e.data.communityListOne;
    var n = a.currentTarget.dataset.index
    var a_id = a.currentTarget.dataset.a_id
    var openid = wx.getStorageSync('openid')
    if (openid == '') {
      wx.showModal({
        title: '提示',
        content: "请先登录",
        success: function (con) {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
        }
      })
    } else if (communityListOne[n].dianzan == 0) {
      app.util.request({
        'url': 'entry/wxapp/share.userdianz',
        data: {
          parentid: a_id,
          openid: openid,
        },
        success: function (res) {
          console.log(res)

        }
      })
      wx.showToast({
        title: "点赞成功",
        icon: "none",
        duration: 1500,
        success: function () {
          var dianzan = "communityListOne[" + n + "].dianzan"
          console.log(dianzan)
          e.setData({
            [dianzan]: 1
          })
        }
      });

    } else {
      wx.showToast({
        title: "点赞是严肃的，不可以反悔哦！",
        icon: "none",
        duration: 1500
      });
    }
  },
  searchbtn() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/search/search',
    })
  },
  dymore() {
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/dynamic/dynamic',
    })
  },

  onLoad: function (t) {
    var a = this;
    app.util.request({
      url: 'entry/wxapp/share.sharesetting',
      success: function (res) {
        console.log(res.data)
        a.setData({
          sharesetting: res.data,
        })
      }
    })
    this.getfooter()
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var index = t.index
    a.setData({
      bgc: bgc,
      index: index
    })

    page = 1;
    a.getAllshare(page, a.data.tabpid);
    a.getShowcategory();
    a.getBase();
  },
  getBase: function () {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/index.base',
      success: function (res) {
        console.log(res);
        that.setData({
          baseinfo: res.data,
        })
        
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },
  onReady: function () { },
  onShow: function () {
    var that = this
    var openid = wx.getStorageSync('openid')
    console.log(openid)
    if (openid) {
      that.setData({
        bigMask: true
      })
    } else {
      that.setData({
        bigMask: false
      })
    }
    // page = 1;
    // that.getAllshare(page);
  },
  onHide: function () { },
  onUnload: function () { },
  onPullDownRefresh: function () { },
  onReachBottom: function () { },
  onShareAppMessage: function () { },
  //发表动态
  addCommunity: function () {
    var openid = wx.getStorageSync('openid')
    if (openid == '') {
      wx.navigateTo({
        url: '/hyb_yl/sgin/sgin',
      })
    } else {
      wx.navigateTo({
        url: "/hyb_yl/userLife/pages/addDynamic/addDynamic"
      });
    }

  },

  //查询首页推荐分享动态分类
  getShowcategory: function () {
    var that = this
    app.util.request({
      url: 'entry/wxapp/share.showcategory',
      success: function (res) {
        that.setData({
          consulList: res.data,
        })
      }
    })
  },

  //查询所有分享
  getAllshare: function (_page, tabpid) {
    var that = this
    that.data.tabpid = tabpid
    console.log(that.data.tabpid)
    app.util.request({
      url: 'entry/wxapp/share.allshare',
      data: {
        openid: wx.getStorageSync('openid'),
        page: _page,
        pagback: 5,
        state: 0,
        labelid: that.data.tabpid
      },
      success: function (res) {
        console.log(res)
        if (res.data.length < 5) {
          that.setData({
            ismore: false
          })
        }
        wx.hideLoading()
        that.setData({
          communityListOne: that.data.communityListOne.concat(res.data),
          page: 1,
        })
      }
    })
  },
  previewImage: function (a) {
    var t = this;
    console.log(a)
    var i = a.currentTarget.dataset.index;
    var url = a.currentTarget.dataset.url
    var artrs = a.currentTarget.dataset.data
    console.log(i, url, artrs)
    wx.previewImage({
      current: url,
      urls: artrs
    });
  },
  scrolltolower() {
    var that = this
    console.log(that.data.ismore)
    if (that.data.ismore) {
      page++;
      console.log(page)
      that.getAllshare(page, that.data.tabpid);
    }
  },
  getfooter() {
    var that = this
    app.util.request({
      url: "entry/wxapp/index.footerlist",
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (resing) {
        let footers = {
          footerTab: that.data.index,
          footerlist: resing.data
        };
        that.setData({
          footer: footers
        })
        console.log(that.data.footer)
      }
    })
  },
});